/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package agent;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Rente
 */
public class TimeVerifier extends Thread {

    private Agent agent;

    public TimeVerifier(Agent agent) {
        this.agent = agent;
        this.start();
    }

    @Override
    public void run() {
        try {
            for (VisitorEntry ve : agent.getVisitorEntries()) {
                if (ve.getAssociationLifetime() > 0) {
                    ve.setAssociationLifetime(ve.getAssociationLifetime() - 1);
                } else if (ve.getAssociationLifetime() == 0) {
                    agent.removeVisitorEntry(ve);
                    agent.sendMessage("localhost", "Confirmation;Error;", 2345);
                }
            }
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            Logger.getLogger(TimeVerifier.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
